

# 也是荷兰国旗问题

class Solution(object):
    def sortColors(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """

        less = -1
        more = len(nums)
        n = 0

        while n < more:
            if nums[n] == 0:
                less += 1
                self.help(nums, less, n)
                n += 1
            elif nums[n] == 2:
                more -= 1
                self.help(nums, more, n)
            else:
                n += 1
    def help(self, nums, a, b):
        nums[a], nums[b] = nums[b], nums[a]